<template>
	<view>

		<u--form :model="candidate" labelWidth="auto" ref="form1">
			<u-form-item label="姓名: " prop="candidate.name" borderBottom ref="item1">
				<u--input v-model="candidate.name" border="bottom" inputAlign="center"></u--input>
			</u-form-item>
			<u-form-item label="电话: " prop="candidate.phone" borderBottom ref="item2">
				<u--input v-model="candidate.phone" border="bottom" inputAlign="center"></u--input>
			</u-form-item>
			<u-form-item label="期望工种: " @tap="showOccupation = true" prop="candidate.occupationId" borderBottom
				ref="item2">
				<u--input v-model="candidate.tbOccupation.name" border="bottom" inputAlign="center" disabled
					disabledColor="#ffffff" placeholder="请选择期望的职业类型"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="性别" prop="candidate.gander" borderBottom @tap="showSex = true;" ref="item1">
				<u--input v-model="candidate.sex" disabled disabledColor="#ffffff" inputAlign="center"
					placeholder="请选择性别" border="bottom">
				</u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="所在城市: " prop="info.tbCity.cityName" @tap="show = true;" borderBottom ref="item3">
				<u--input v-model="candidate.tbCity.cityName" border="bottom" inputAlign="center" disabled
					disabledColor="#ffffff" placeholder="请选择工作城市"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="期望薪资: " prop="candidate.wantSalary" borderBottom ref="item3">
				<u--input v-model="candidate.wantSalary" border="bottom" inputAlign="center"></u--input>
			</u-form-item>
			<u-form-item label="详细地址: " prop="candidate.address" borderBottom ref="item2">
				<u--input v-model="candidate.address" border="bottom" inputAlign="center"></u--input>
			</u-form-item>
			<u-form-item label="自我介绍: " prop="candidate.selfIntroduction" ref="item1">
				<u--textarea v-model="candidate.selfIntroduction" placeholder="请输入内容"></u--textarea>
			</u-form-item>
			<u-picker :show="show" ref="uPicker" :columns="cityList" @confirm="confirm()" keyName="cityName"
			@change="changeCity"></u-picker>
		</u--form>
		<u-action-sheet :show="showOccupation" :actions="occupationList" title="请选择职业类型" @close="showOccupation = false"
			@select="selectOccupation">

		</u-action-sheet>
		<u-action-sheet :show="showSex" :actions="actions" title="请选择性别" @close="showSex = false" @select="sexSelect">
		</u-action-sheet>
		<view>
			<u-button type="primary" @click="updateCandidate()" icon="plus">保存信息</u-button>
		</view>
	</view>
</template>

<script>
	import {
		findAllCityChild
	} from "../../api/city.js"
	import {
		getCandidatesById,
		findAlloccupation,
		updateCandidate
	} from '@/api/enterprise.js'
	import {
		Toast
	} from '../../common/common.js'
	export default {
		data() {
			return {
				candidate: {
					sex: ''
				},
				occupationList: [],
				showOccupation: false,
				actions: [{
						name: '男',
						id: '0'
					},
					{
						name: '女',
						id: '1'
					}
				],
				showSex: false,
				cityList:[],
				show:false
			}
		},
		methods: {
			confirm(e) {
				this.candidate.cityId = e.value[0].cityId
				this.candidate.tbCity = e.value[0]
				this.show = false
			},
			changeCity(e) {},
			findAllCityChild() {
				findAllCityChild({}).then(res => {
					this.cityList.push(res.data.data)
				})
			},
			getCandidatesById() {
				getCandidatesById({
					'id': this.candidate.id
				}).then(res => {
					this.candidate = res.data.data
					this.candidate.sex = this.candidate.gender == '0' ? '男' : '女'
				})
			},
			findOccupation() {
				findAlloccupation().then(res => {
					this.occupationList = res.data.data
				})
			},
			selectOccupation(e) {
				this.candidate.occupationId = e.id
				this.candidate.tbOccupation.name = e.name
			},
			sexSelect(e) {
				this.candidate.sex = e.name
				this.candidate.gender = e.id
			},
			updateCandidate(){
				updateCandidate(this.candidate).then(res=>{
					if(res.data.code==20000){
						uni.navigateBack({
							url:'pages/self/self'
						})
						Toast({title:res.data.message})
					}else{
						Toast({title:res.data.message})
					}
					
				})
		},
		onLoad(options) {
			this.candidate.id = options.id
			this.getCandidatesById()
			this.findOccupation()
			this.findAllCityChild()
		},
		
		}
	}
</script>

<style>

</style>
